//
//  YDAHomeTableCell.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/23.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "YDAHomeTableCell.h"
#import "YDAStockRiseFallModel.h"



@interface YDAHomeTableCell()

@property (nonatomic , weak) UIView *lineView;
//名称
@property (nonatomic , weak) UILabel *stockName;
//代码
@property (nonatomic , weak) UILabel *stockCode;
//最新价
@property (nonatomic , weak) UILabel *stockNewPrice;
//涨跌幅
@property (nonatomic , weak) UILabel *stockUpRate;


@end

@implementation YDAHomeTableCell


-(void)setModel:(YDAStockRiseFallModel *)model
{
    _model = model;
    self.stockName.text = model.name;
    self.stockCode.text = model.instrumentId;
    self.stockNewPrice.text = model.pzLastPrice;
    self.stockUpRate.text = model.persentUpDown;
    if (model.priceColor == Price_Up) {
        self.stockUpRate.textColor = [UIColor colorWithHexString:paleRed];
        self.stockNewPrice.textColor = [UIColor colorWithHexString:paleRed];
    }else if (model.priceColor == Price_Down){
        self.stockUpRate.textColor = [UIColor colorWithHexString:leafyGreen];
        self.stockNewPrice.textColor = [UIColor colorWithHexString:leafyGreen];
    }else{
        self.stockUpRate.textColor = [UIColor colorWithHexString:dark];
        self.stockNewPrice.textColor = [UIColor colorWithHexString:leafyGreen];
    }
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *aHomeTableCell = @"YDAHomeTableCell";
    YDAHomeTableCell *cell = [tableView dequeueReusableCellWithIdentifier:aHomeTableCell];
    if (cell == nil) {
        cell = [[YDAHomeTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:aHomeTableCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.backgroundColor = [UIColor whiteColor];
        [self bgView];
        [self lineView];
        
        [self stockName];
        [self stockCode];
        [self stockNewPrice];
        [self stockUpRate];
        
        
    }
    return self;
}

-(UIView *)bgView
{
    if (_bgView == nil) {
        _bgView = [UIView new];
        [self.contentView addSubview:_bgView];
        _bgView.backgroundColor = self.contentView.backgroundColor;
        [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.equalTo(self.contentView);
        }];
    }
    return _bgView;
    
    
}

-(UILabel *)stockName
{
    if (_stockName == nil) {
        UILabel *stockName = [[UILabel alloc] init];
        [self.contentView addSubview:stockName];
        stockName.textColor = [UIColor colorWithHexString:dark];
        stockName.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        stockName.textAlignment = NSTextAlignmentLeft;
        stockName.text = @"贵州茅台";
        [stockName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(rate375(20));
            if (isPhoneX) {
                make.top.equalTo(self).offset(rateX812(8));
            }else{
                make.top.equalTo(self).offset(rate750(8));
            }
        }];
        _stockName = stockName;
    }
    return _stockName;
}

-(UILabel *)stockCode
{
    if (_stockCode == nil) {
        UILabel *stockCode = [[UILabel alloc] init];
        [self.contentView addSubview:stockCode];
        stockCode.textColor = [UIColor colorWithHexString:@"687284"];
        stockCode.font = [UIFont systemFontOfSize:font10ScreenWRate * LKScreenW];
        stockCode.textAlignment = NSTextAlignmentLeft;
        stockCode.text = @"600519";
        [stockCode mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(rate375(20));
            if (isPhoneX) {
                make.top.equalTo(self.stockName.mas_bottom).offset(rateX812(5));
            }else{
                make.top.equalTo(self.stockName.mas_bottom).offset(rate750(5));
            }
        }];
        _stockCode = stockCode;
    }
    return _stockCode;
}

-(UILabel *)stockNewPrice
{
    if (_stockNewPrice == nil) {
        UILabel *stockNewPrice = [[UILabel alloc] init];
        [self.contentView addSubview:stockNewPrice];
        stockNewPrice.textColor = NumberColor(222, 95, 65);
        stockNewPrice.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        stockNewPrice.textAlignment = NSTextAlignmentLeft;
        stockNewPrice.text = @"782.52";
        [stockNewPrice mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self);
        }];
        _stockNewPrice = stockNewPrice;
    }
    return _stockNewPrice;
}

-(UILabel *)stockUpRate
{
    if (_stockUpRate == nil) {
        UILabel *stockUpRate = [[UILabel alloc] init];
        [self.contentView addSubview:stockUpRate];
        stockUpRate.textColor = NumberColor(222, 95, 65);
        stockUpRate.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        stockUpRate.textAlignment = NSTextAlignmentRight;
        stockUpRate.text = @"+4.12%";
        [stockUpRate mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.right.equalTo(self).offset(-rate375(20));
        }];
        _stockUpRate = stockUpRate;
    }
    return _stockUpRate;
}

-(UIView *)lineView
{
    if (_lineView == nil) {
        UIView *lineView = [[UIView alloc] init];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = [UIColor colorWithHexString:mainGray];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
            make.height.equalTo(@1);
        }];
        _lineView = lineView;
    }
    return _lineView;
}




@end
